package org.platform.common.result;

import java.io.Serializable;

/**
 * <pre>
 * 功能：业务返回对象
 * </pre>
 * 
 * @author wei.gao
 * @param <T>
 */
public class ServiceResult<T> extends ServiceResponse<T> implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1803300657518456150L;
	
	/**
	 * 异常
	 */
	private Exception exception;
	
	public Exception getException() {
		return exception;
	}

	/**
	 * <pre>
	 * 功能：失败
	 * </pre>
	 * @param code
	 * @param message
	 * @param exception
	 * @return
	 */
	public ServiceResult<T> failure(String code, String message, Exception exception) {
		this.exception = exception;
		super.failure(code, message);
		return this;
	}
	
    /**
     * <pre>
     * 功能：判断返回结果是否有异常
     * </pre>
     * @return
     */
    public boolean hasException() {
        return exception != null;
    }
	
	/**
	 * <pre>
	 * 功能：判断返回结果是否成功
	 * </pre>
	 * @return
	 */
    public boolean isSuccess() {
        return !hasException() && "10000".equals(this.code);
    }

    /**
     * <pre>
     * 功能：判断返回结果是否有结果对象
     * </pre>
     * @return
     */
    public boolean hasObject() {
        return isSuccess() && data != null;
    }

}